package com.winderinfo.yikaotianxia.ui.zhuanye;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.core.api.Api;
import com.winderinfo.yikaotianxia.core.base.BaseActivity;
import com.winderinfo.yikaotianxia.core.mvp.Contract;
import com.winderinfo.yikaotianxia.core.mvp.Presenter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MajorList extends BaseActivity implements Contract.View {
    @BindView(R.id.ma_banck)
    ImageView maBanck;
    @BindView(R.id.ma_recycle)
    RecyclerView maRecycle;
    private Presenter presenter;
    Map<String, Object> map = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected int initLayoutId() {
        return R.layout.activity_majirlist;
    }

    @Override
    protected void initView() {
        //实例P
        presenter = new Presenter(this);
        //列表管理器
        GridLayoutManager gridLayoutManager = new GridLayoutManager(MajorList.this, 2);
        maRecycle.setLayoutManager(gridLayoutManager);
    }

    @Override
    protected void initData() {
        //请求专业列表
        /**
         * @pageNum 页码
         * @pageSize 每页数量
         * */
        map.clear();
        map.put("pageNum", 1);
        map.put("pageSize", 12);
        presenter.onPostRequest(Api.HOME_ZHUANYE, null, MajorListBean.class);
    }

    @Override
    public void onSuccess(Object data) {
        if (data instanceof MajorListBean) {
            List<MajorListBean.RowsBean> rows = ((MajorListBean) data).getRows();
            MajorListAdapter majorListAdapter = new MajorListAdapter(this, rows);
            maRecycle.setAdapter(majorListAdapter);
            //
            majorListAdapter.setOnMId(new MajorListAdapter.OnMId() {
                @Override
                public void getId(int id) {
                    openActivity(MajorIntroduceActivity.class);
                }
            });
        }

    }

    @Override
    public void onFailure(Object error) {
        finish();
        ;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onUntying();
    }

    @OnClick(R.id.ma_banck)
    public void onViewClicked() {
        finish();
    }
}
